import * as api from '@/views/case_module/api'
export const crudOptions = (vm) => {
  return {
    rowHandle: {
      dropdown: { // 操作列折叠
        atLeast: 0, // 至少几个以上的按钮才会被折叠,注意show=false的按钮也会计算在内（行编辑按钮默认是隐藏的也会占一个位置）
        text: '操作', // dropdown按钮文字
        type: 'primary',
        icon: 'el-icon-more'
      },
      width: 150,
      view: {
        disabled () {
          // return false
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        disabled () {
          // return false
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        disabled () {
          // return false
          return !vm.hasPermissions('Delete')
        }
      },
      custom: [
        {
          thin: true,
          text: '调试',
          size: 'small',
          type: 'warning',
          icon: 'el-icon-video-play',
          show () {
            // return vm.hasPermissions('CaseTest')
            return true
          },
          emit: 'caseTest'
        },
        {
          thin: true,
          text: '查看结果',
          size: 'small',
          icon: 'el-icon-files',
          show () {
            // return vm.hasPermissions('CaseResult')
            return true
          },
          emit: 'showCaseResult'
        }
      ],
      fixed: 'right'
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false
    },
    formOptions: { // 表单宽度
      type: 'drawer',
      draggable: false, // 关闭拖拽
      fullscreen: false, // 关闭全屏功能
      size: '50%'
    },
    indexRow: { // 序号
      title: '序号',
      align: 'center',
      width: 60
    },
    selectionRow: { // 多选框
      align: 'center',
      width: 46
    },
    columns: [
      {
        title: 'Id',
        key: 'id',
        view: { disabled: true },
        form: { // 表单配置
          disabled: true // 禁用表单编辑
        },
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        disabled: true, // 隐藏列
        sortable: false
      },
      {
        title: '用例名称',
        key: 'case_name',
        // type: 'select',
        // dict: { url: ''}, //数据字典
        search: { disabled: false }, // 开启查
        showOverflowTooltip: true,
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '用例名称' }],
          component: {
            span: 24,
            props: {
              clearable: true
            },
            placeholder: '请输入用例名称'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '运行环境',
        key: 'host_belong',
        type: 'radio',
        width: 150,
        dict: {
          cache: false,
          url: '/test_manage/host_manage',
          value: 'id',
          label: 'host_name'
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '运行环境' }],
          component: {
            span: 24,
            props: {
              multiple: false, clearable: true
            },
            placeholder: '请选择运行环境'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '所属项目',
        key: 'project_belong',
        type: 'select',
        width: 150,
        dict: {
          cache: false,
          url: '/quality/project/',
          value: 'id',
          label: 'project_name'
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        view: { disabled: true },
        form: { // 表单配置
          disabled: true, // 禁用表单编辑
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择所属项目'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColumn, mode, component, immediate, getComponent }) {
            form.module_belong = undefined // 将“module_belong”的值置空
            if (value) {
              getComponent('module_belong').reloadDict() // 执行city的select组件的reloadDict()方法，触发“city”重新加载字典
            }
          }
        },
        sortable: false
      },
      {
        title: '所属模块',
        key: 'module_belong',
        type: 'tree-selector',
        width: 150,
        dict: {
          isTree: true,
          label: 'module_name',
          value: 'id',
          cache: false,
          getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
            return api.ModuleLazy().then(ret => { return ret })
          }
        },
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '用例模块' }],
          component: {
            span: 12,
            props: {
              multiple: false, clearable: true
            },
            placeholder: '请选择用例模块'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '用例类型',
        key: 'case_type',
        type: 'select',
        width: 200,
        dict: {
          data: vm.dictionary('case_type')
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '用例类型' }],
          component: {
            span: 12,
            props: {
              clearable: true
            },
            placeholder: '请选择用例类型'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColum, mode, component, immedite, getComponent }) {
            if (value && (value === 0 || value === 1)) {
              form.http_method = undefined
              form.socket_method = undefined
              form.url = undefined
              form.params_type = undefined
              form.headers = undefined
              form.jsonbody = undefined
              form.params = undefined
            }
          }
        },
        sortable: false
      },
      {
        title: '请求方法',
        key: 'http_method',
        type: 'select',
        dict: {
          data: vm.dictionary('http_method')
        }, // 数据字典
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: 'HTTP请求方法' }],
          component: {
            show (context) {
              return context.form.case_type === 1
            },
            span: 8,
            props: {
              clearable: true
            },
            placeholder: '请选择HTTP请求方法'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColum, mode, component, immedite, getComponent }) {
            if (value && (value === 0 || value === 2)) {
              form.socket_method = undefined
              form.url = undefined
              form.params_type = undefined
              form.headers = undefined
              form.jsonbody = undefined
              form.params = undefined
            }
          }
        },
        sortable: false
      },
      {
        title: '请求方法',
        key: 'socket_method',
        type: 'select',
        dict: {
          cache: false,
          data: vm.dictionary('socket_method')
        }, // 数据字典
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: 'SOCKET方法' }],
          component: {
            show (context) {
              return context.form.case_type === 0
            },
            span: 6,
            props: {
              clearable: true
            },
            placeholder: '请选择SOCKET方法'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColum, mode, component, immedite, getComponent }) {
            if (value && value === 0) {
              form.http_method = undefined
              form.url = undefined
              form.params_type = undefined
              form.headers = undefined
              form.jsonbody = undefined
              form.params = undefined
            }
          }
        },
        sortable: false
      },
      {
        key: 'url',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            show (context) {
              return (context.form.case_type === 0 && context.form.socket_method === 0) || context.form.case_type === 1
            },
            span: 16,
            placeholder: '请输入URL'
          },
          itemProps: {
            labelWidth: '0px'
          }
        },
        sortable: false
      },
      {
        title: '参数类型',
        key: 'params_type',
        type: 'radio',
        dict: {
          data: vm.dictionary('params_type')
        }, // 数据字典
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            show (context) {
              return context.form.case_type === 1 && (context.form.http_method === 0 || context.form.http_method === 2)
            },
            span: 24,
            props: {
              clearable: true
            },
            placeholder: '请选择参数类型'
          },
          valueChange (key, value, form, { getColum, mode, component, immedite, getComponent }) {
            if (value) {
              form.headers = undefined
              form.jsonbody = undefined
              form.params = undefined
            }
          }
        },
        sortable: false
      },
      {
        title: '头部信息',
        key: 'headers',
        disabled: true, // 隐藏列
        form: { // 表单配置
          slot: true,
          disabled: false, // 禁用表单编辑
          component: {
            span: 24,
            show (context) {
              return context.form.case_type === 1 && (context.form.http_method === 1 || ((context.form.http_method === 0 || context.form.http_method === 2) && context.form.params_type === 0))
            },
            props: {
              clearable: true
            },
            placeholder: '请输入头部信息'
          }
        },
        sortable: false
      },
      {
        title: 'Json参数',
        key: 'jsonbody',
        disabled: true, // 隐藏列
        form: { // 表单配置
          slot: true,
          disabled: false, // 禁用表单编辑
          component: {
            span: 24,
            show (context) {
              return context.form.case_type === 0 || (context.form.case_type === 1 && (context.form.http_method === 0 || context.form.http_method === 2) && context.form.params_type === 1)
            },
            props: {
              clearable: true
            },
            placeholder: '请输入Json参数'
          }
        },
        sortable: false
      },
      {
        title: '普通参数',
        key: 'params',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            span: 19,
            show (context) {
              return ((context.form.http_method === 0 || context.form.http_method === 2) && context.form.case_type !== 0) && context.form.params_type === 2
            },
            props: {
              clearable: true
            },
            placeholder: '请输入普通参数'
          }
        },
        sortable: false
      },
      {
        title: '文件路径',
        key: 'file_path',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            span: 24,
            show (context) {
              return context.form.case_type === 4
            },
            props: {
              clearable: true
            },
            itemProps: {
              class: { yxtInput: true }
            },
            placeholder: '请输入文件路径'
          }
        },
        sortable: false
      },
      {
        title: '检查点',
        key: 'verification',
        form: { // 表单配置
          component: {
            placeholder: '请输入检查规则'
          },
          disabled: false // 禁用表单编辑
        },
        disabled: true, // 隐藏列
        sortable: false
      },
      {
        title: '提取参数',
        key: 'extract',
        form: { // 表单配置
          component: {
            placeholder: '请输入提取规则'
          },
          disabled: false // 禁用表单编辑
        },
        disabled: true, // 隐藏列
        sortable: false
      },
      {
        title: '用例排序',
        key: 'sort',
        width: 150,
        showOverflowTooltip: true,
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            placeholder: '请输入用例排序'
          }
        },
        sortable: false
      }
    ].concat(vm.commonEndColumns({
      create_datetime: { showTable: false },
      modifier_name: { showTable: true }
    }))
  }
}
